package cn.util.common;

import lombok.Data;

@Data
public class Result<T>{
    //返回消息
    private String message;
    //返回状态码
    private Integer code;
    //返回内容
    private T data;

    public Result(){

    }


    /**
     * 没有返回数据的返回
     * @param <T>
     * @return
     */
    public static <T> Result<T> ok(){
        return Result.ok(null);
    }

    /**
     * 带返回数据的返回
     */
    public static <T> Result<T> ok(T data){
        Result result=new Result();
        result.setCode(ResultCodeEnum.SUCCESS.getCode());
        result.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }

    /**
     * 自定义返回信息
     */
    public static <T> Result<T> customResult(Integer code,String message){
        Result result=new Result();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    /**
     * 返回一个错误的信息
     */
    public static <T> Result<T> fall(){
        Result result=new Result();
        result.setMessage(ResultCodeEnum.FALL.getMessage());
        result.setCode(ResultCodeEnum.FALL.getCode());
        return result;
    }

    /**
     * 自定一个错误的返回信息
     */
    public static <T> Result<T> fall(Integer code,String message){
        Result result=new Result();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }



}
